﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using DataAccess.Classes;

public partial class Controls_CatList : System.Web.UI.UserControl
{
    string maThuongHieu = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        maThuongHieu = Request.QueryString["CategoryID"];
        // Chi tai du lieu khi trang web tai lan dau tien, postback thi bo qua 
        if (!IsPostBack)
            PopulateControls(); 
    } 
    // Lay danh sach cac category
    private void PopulateControls()
    { 
        repCatList.DataSource = ThuongHieu.All();
        repCatList.DataBind();
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e); 
        // Them su kien cho Repeater 
        repCatList.ItemDataBound += new RepeaterItemEventHandler(repCatList_ItemDataBound); 
    } 
    // Xy ly su kien ItemDataBound cua Repeater 
    void repCatList_ItemDataBound(object sender, RepeaterItemEventArgs e) 
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        { 
            // Lay du lieu hien tai 
            ThuongHieu data = e.Item.DataItem as ThuongHieu; 
            string id = data.MaThuongHieu.ToString();
            // Lay control (phan to dam) trong source html ở trên 
            HyperLink lnkCat = (HyperLink)e.Item.FindControl("lnkCat"); 
            lnkCat.Text = data.TenThuongHieu;
            lnkCat.NavigateUrl = Link.ToCategory(id); 
            // Them CSS cho category hien tai 
            lnkCat.CssClass = id == maThuongHieu ? "current" : "";
            lnkCat.ToolTip = data.TenThuongHieu; 
        } 
    }
}